stage.set_background("halfcourt")
sprite = codesters.Sprite("player4")
sprite.go_to(215, -175)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
ball = codesters.Sprite("basketball")
x = random.randint(-100, 150)
ball.go_to(x, -25)
stage.set_gravity(10)
stage.set_bounce(.8)
ball.set_gravity_off()
net.set_gravity_off()
left_count = 0
down_count = 0
def left_key():
ball.move_left(10)
# add other actions...
global left_count
stage.event_key("left", left_key)
t = codesters.Teacher()
try:
tval1 = t.find_text('+=')[0][1]
tval2 = t.find_text('+=')[0][0]
tval2 = t.get_indent_at_line(tval2)
except:
tval1 = "DNE"
tval2 = "DNE"
t1 = TestObjective()
t1.add_success(tval1.replace(' ', '') == 'left_count+=1' and tval2 == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add an Add Value command to your Left Key event?")
t1.add_failure('left_count' not in tval1, "Make sure you change the name of the variable in the Add Value command to left_count.")
t1.add_failure('1' not in tval1, "Make sure the value that you;re adding to the variable is 1.")
t1.add_failure(tval2 < 4, "Make sure your Add Value command is indented 4 spaces inside you Left Key event.")
t1.add_failure(tval2 > 4, "Oops! You indented too far. Make sure your Add Value command is only 4 spaces inside your Left Key event.")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)